<?php
/**
 * Created by PhpStorm.
 * User: rocky
 * Date: 2019-07-14
 * Time: 01:24
 */

namespace app\shop\resource;

use app\common\resource\BaseResource;

class CardsResoure extends BaseResource
{
    public function toArray($data)
    {
        if ($data['member'][0]){
            $member_staus = true;
            $start_time = $data['member'][0]['expire_time'];
            $is_open = true;
        }else{
            $start_time = time();
            $member_staus = false;
            $is_open = false;
        }
        switch ($data['type']) {
            case 2:
                if ($member_staus) {
                    $end_time =  strtotime("+ 1 month",$start_time);
                }else{
                    $end_time =  strtotime("+ 1 month",time());
                }
                break;
            case 3:
                if ($member_staus) {
                    $end_time =  strtotime("+ 3 month",$start_time);
                }else{
                    $end_time =  strtotime("+ 3 month",time());
                }
                break;
            default:
                if ($member_staus) {
                    $end_time =  strtotime("+ ".$data['effective_date']." day",$start_time);
                }else{
                    $end_time =  strtotime("+ ".$data['effective_date']." day",time());
                }
                break;
        }
        return [
            'id' => $data['id'],
            'name' => $data['name'],
            'money' => $data['money'],
            'wash_number' => $data['wash_number'],
            'describe' => $data['describe'],
            'content' => $data['content'],
            'start_time' =>  date('Y-m-d',$start_time),
            'end_time' =>  date('Y-m-d',$end_time),
            'user_money'=> $data['user_money'],
            'is_open' => $is_open
        ];
    }

}